module.exports = {
	/**
	 * 添加用户
	 * @url 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @param {Number} code 错误码，0表示成功
	 * @param {String} msg 详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		let dbName = "bus-wx-config";
		var id
		if(data.uid) delete data.uid
		if(data._id){
			id = data._id
			delete data._id
		}
		if(data.config_key === 'base_config' && (!data.copyright_text || !data.copyright_logo)){
			data.copyright_text = encodeURIComponent('猫优壁纸·技术支持')
			data.copyright_logo = encodeURIComponent('https://wall.maoeu.cn/logo.png')
		}
		if(id){
			res.num = await vk.baseDao.updateById({
				dbName: dbName,
				id: id,
				dataJson: data
			});
		}else{
			res.num = await vk.baseDao.add({
				dbName: dbName,
				dataJson: data
			});
		}
		//更新配置，清除配置缓存
		vk.globalDataCache.del('wx_home')
		vk.globalDataCache.del('qq_home')
		vk.globalDataCache.del('tt_home')
		vk.globalDataCache.del('ks_home')
		//更新配置，清除配置缓存
		vk.globalDataCache.del('wx_center')
		vk.globalDataCache.del('qq_center')
		vk.globalDataCache.del('tt_center')
		vk.globalDataCache.del('ks_center')
		//更新配置，清除配置缓存
		vk.globalDataCache.del('wx_setting')
		vk.globalDataCache.del('qq_setting')
		vk.globalDataCache.del('tt_setting')
		vk.globalDataCache.del('ks_setting')
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}